package com.yuke.cloud.common.security.core.social.view;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.view.AbstractView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 绑定结果视图
 *
 * @author
 */
public class PcConnectView extends AbstractView {

	private static final String CONNECTIONS = "connections";

	@Value("${spring.profiles.active}")
	private String env;//当前激活的配置文件

	/**
	 * Render merged output model.
	 *
	 * @param model    the model
	 * @param request  the request
	 * @param response the response
	 *
	 * @throws Exception the exception
	 */
	@Override
	protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
	                                       HttpServletResponse response) throws Exception {

		//add by wg 20181215 如果开发环境加上跨域配置（由于response直接输出，无法在配置类中进行配置，因此在response前直接配置跨域，生产环境在网关中已配置）
		if ("dev".equals(env)) { //开发环境对跨域进行配置
			response.setHeader("Access-Control-Allow-Origin", "*");
			response.setHeader("Access-Control-Allow-Credentials", "true");
			response.setHeader("Access-Control-Allow-Headers", "*");
		}

		response.setContentType("text/html;charset=UTF-8");
		if (model.get(CONNECTIONS) == null) {
			response.getWriter().write("<h3>解绑成功</h3>");
		} else {
			response.getWriter().write("<h3>绑定成功</h3>");
		}

	}

}
